#!/usr/bin/env node

const http = require('http'),
      log  = console.log,
      url  = require('url'),
      addr = 'http://www.sian.com/';

let opt = (add) => {
  let p = url.parse(add);
  p.headers = {
    'user-agent' : 'curl/7.29.0'
  };
  return p;
};

get(opt(addr));

function get(add){
  http.get(opt(add),(res) => {
    log(`HTTP/${res.httpVersion} ${res.statusCode} ${res.statusMessage}`);

    log(res.headers);

    log();

    if(res.statusCode >= 300 && res.statusCode < 400){
      get(res.headers.location);
    }else{
      res.pipe(process.stdout);
    }
  });
}
